/*
 * Project Name sprint-boot-tools
 * File Name Treminate
 * Package Name com.huxiaosu.tools.cmpp.service.action
 * Create Time 2024/5/6
 * Create by name：liujie
 */
package com.huxiaosu.tools.cmpp.action;

import com.huxiaosu.tools.cmpp.enums.CommandId;
import com.huxiaosu.tools.cmpp.model.MessageHeader;
import com.huxiaosu.tools.cmpp.model.action.TerminateMsg;
import com.huxiaosu.tools.cmpp.action.AbstractMessageAction;
import lombok.extern.slf4j.Slf4j;
import org.apache.mina.core.buffer.IoBuffer;
import org.springframework.stereotype.Component;

/**
 * SP 或 ISMG 请求拆除连接（CMPP_TERMINATE）操作
 *
 * @author liujie
 * @date 2024/5/6 20:27
 */
@Slf4j
@Component
public class TerminateAction extends AbstractMessageAction {

    @Override
    public CommandId getMessageCommandId() {
        return CommandId.CMPP_TERMINATE;
    }

    @Override
    public String getMessageCommandName() {
        return CommandId.CMPP_TERMINATE.name();
    }

    @Override
    public MessageHeader readMessage(IoBuffer ioBuffer) {
        return new TerminateMsg();
    }

    @Override
    public void execute() {
        log.warn("<链接已断开>");
        MessageHeader terminateMsg = new MessageHeader(CommandId.CMPP_TERMINATE_RESP.getMsgLength(),
                CommandId.CMPP_TERMINATE_RESP.getCommand(), super.message.getSequenceId());
        session.write(terminateMsg.toBytes());
    }

}